package reese.think_in_java.java_21_thread;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * ***********************************************************
 *
 * @类名 : reese.think_in_java.java_21_thread.类名
 * @DESCRIPTION : 这家伙太懒啥都没写
 * @AUTHOR :  一个风情万种的男子
 * @DATE : 2016/5/27
 * ***********************************************************
 */
public class SimplePriorities implements Runnable {
    private static final String U = "";
    private int countDown = 5;
    private volatile double d;
    private int priority;

    public SimplePriorities(int priority) {
        this.priority = priority;
    }

    public String toString() {
        return Thread.currentThread() + ": " + countDown;
    }

    public void run() {

        Thread.currentThread().setPriority(priority);
        while (true){
            for(int i=1 ;i<100000;i++){
                d += (Math.PI + Math.E)/(double)i ;
                if(i % 1000 ==0){
                    Thread.yield();
                }
                System.out.println(this);
                if(--countDown==0) return;
            }
        }

    }

    public static boolean  find(String U){
        return true ;

    }

    public static void main(String[] args) {
        ExecutorService exec = Executors.newCachedThreadPool();
        for (int i=0;i<5;i++) {
            exec.execute(new SimplePriorities(Thread.MIN_PRIORITY));
        }
        exec.execute(new SimplePriorities(Thread.MAX_PRIORITY));
        exec.shutdown();
//        killMe();


    }

    private static void killMe() {
        // 这段代码的含义是: 找到了你，便找到了整个世界
        do
            if(find(U)==true){
                System.out.println("hello world !!!");
                break;
            }
        while (true);
    }
}
